package com.mmall.common;

import com.google.common.collect.Sets;

import java.util.Set;

public class Const {
    public static final String CURRENT_USER = "currentUser";

    public static final String EMAIL = "email";
    public static final String USERNAME = "username";

    public interface Role {
        int ROLE_CUSTOMER = 0; // 普通用户
        int ROLE_ADMIN = 1; // 管理员

    }

    public interface ProductListOrderBy {
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_desc","price_asc");
    }

    public interface Cart{
        int CHECKED = 1; // 购物车选中状态
        int UN_CHECKED = 0; // 未选中状态

        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
    }

    public interface AlipayCallback{
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY"; //交易创建，等待买家付款
        String TRADE_STATUS_TRADE_CLOSED = "TRADE_CLOSED"; // 未付款交易超时关闭，或支付完成后全额退款
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS"; // 交易支付成功
        String TRADE_STATUS_TRADE_FINISHED = "TRADE_FINISHED"; // 交易结束，不可退款

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }

    public enum ProductStatus {
        ON_SALE("在线", 1);
        private String value;
        private int code;

        ProductStatus(String value, int code) {
            this.value = value;
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }

    public enum OrderStatus {
        CANCELED("已取消", 0),
        NO_PAY("未支付", 10),
        PAID("已付款", 20),
        SHIPPED("已发货", 40),
        ORDER_SUCCESS("订单完成", 50),
        ORDER_CLOSED("订单关闭", 60)
        ;

        private String value;
        private int code;

        OrderStatus(String value, int code) {
            this.value = value;
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }

        public static OrderStatus codeOf(int code){
            for(OrderStatus orderStatus : values()){
                if(orderStatus.getCode() == code){
                    return orderStatus;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }

    public enum PayPlatform {
        ALIPAY("支付宝", 1)
        ;
        private String value;
        private int code;

        PayPlatform(String value, int code) {
            this.value = value;
            this.code = code;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }

    public enum PaymentType {
        ONLINE_PAY(1, "在线支付")
        ;

        PaymentType(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public String getValue() {
            return value;
        }

        private int code;
        private String value;

        public static PaymentType codeOf(int code){
            for(PaymentType paymentType : values()){
                if(paymentType.getCode() == code){
                    return paymentType;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }
}
